package duyd.mvc.training.service.jpa;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import duyd.mvc.training.domain.Contact;
import duyd.mvc.training.repository.ContactRepository;
import duyd.mvc.training.service.ContactService;

@Repository
@Service("contactService")
@Transactional
public class ContactServiceImpl implements ContactService {

	@Autowired
	ContactRepository contactRepository;

	@Transactional(readOnly = true)
	public List<Contact> findAll() {
		return (List<Contact>) contactRepository.findAll();
	}

	@Transactional(readOnly = true)
	public Contact findById(Long id) {
		return contactRepository.findOne(id);
	}

	public Contact save(Contact contact) {
		contactRepository.save(contact);
		return contact;
	}

}
